import java.util.Random;

/***
 * 测试LoopQueue和ArrayQueue之间的性能差别
 */
public class QueueMain {

    public static double testQueue(Queue<Integer> q,int times){
        Random random = new Random();
        long time1 = System.nanoTime();
        for(int i=0;i<times;i++){
            q.enqueue(random.nextInt());
        }
        for(int i=0;i<times;i++){
            q.dequeue();
        }

        long time2 = System.nanoTime();
        return (time2 - time1) / 1000000000.0;

    }

    public static void main(String[] args) {
        int times = 10000;

        //测试10w次loopqueue花费时间
        LoopQueue<Integer> loopQueue = new LoopQueue<>();
        double looptime = testQueue(loopQueue, times);
        System.out.println("loopQueue time : " + looptime);

        //测试10w次arrayqueue花费时间
        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        double arraytime = testQueue(arrayQueue, times);
        System.out.println("arrayQueue time : " + arraytime);
    }
}
